package com.work.demo.controller;

import com.work.demo.redis.RedisStorageService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
public class RedisTestController {

    @Resource(name = "RedisStorageStrServiceImpl")
    private RedisStorageService redisStorageService;

    private static final String KEY = "lin-ya";

    @GetMapping("/addKey")
    public void add(){
        redisStorageService.add(KEY,"123456");
    }

    @GetMapping("/getKey")
    public String get(){
        return redisStorageService.getValue(KEY);
    }


    @GetMapping("/delKey")
    public void del(){
       redisStorageService.del(KEY);
    }

    @GetMapping("/exKey")
    public boolean ex(){
        return redisStorageService.expired(KEY,2L, TimeUnit.MINUTES);
    }

    @GetMapping("/tail")
    public boolean tail(){
        try {
            Thread.sleep(50000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return true;
    }
}
